/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<int> inorderTraversal(TreeNode* root) {
        /*if(!root)
            return {};
        inorderTraversal(root->left);
        nums.push_back(root->val);
        inorderTraversal(root->right);
        return nums;
    }
    vector<int> nums;*/
        if (!root)
            return {};
        vector<int> nums;
        stack<TreeNode*> st;
        while (root || !st.empty())
        {
            while (root)
            {
                st.push(root);
                root = root->left;
            }
            nums.push_back(st.top()->val);
            root = st.top()->right;
            st.pop();
        }
        return nums;
    }
};